package tx.bjdacp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;

import cn.org.rapid_framework.test.context.TestMethodContext;
import static junit.framework.Assert.*;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import tx.bjdacp.model.*;
import tx.bjdacp.dao.*;
import tx.bjdacp.service.*;
import tx.bjdacp.vo.query.*;


public class ArchiveCatalogManagerTest extends BaseManagerTestCase{
	protected Log log = LogFactory.getLog(getClass());
	private ArchiveCatalogManager manager;

	@Autowired
	public void setArchiveCatalogManager(ArchiveCatalogManager manager) {
		this.manager = manager;
	}

	private DrugSellUnitManager dsu_manager;

	@Autowired
	public void setDrugSellUnitManager(DrugSellUnitManager dsu_manager) {
		this.dsu_manager = dsu_manager;
	}

    @Override
    protected String[] getDbUnitDataFiles() {
        //通过 TestMethodContext.getMethodName() 可以得到当前正在运行的测试方法名称
        return new String[]{"classpath:testdata/common.xml","classpath:testdata/ArchiveCatalog.xml",
                            "classpath:testdata/ArchiveCatalog_"+TestMethodContext.getMethodName()+".xml"};
    }

    /**
     * 初始化药监档案案卷目录数据，关联到对应的药品经营企业
     */
    @Test
    @Rollback(false)
    public void initData(){
    	List<ArchiveCatalog> acs=manager.findAll();
    	for (ArchiveCatalog archiveCatalog : acs) {
    		DrugSellUnit dsu=dsu_manager.findByFileNumber(archiveCatalog.getFileNumber());
    		if(dsu!=null){
    			log.info(dsu.getDrugSellUnitId());
    			archiveCatalog.setDrugSellUnitId(dsu.getDrugSellUnitId());
    			manager.update(archiveCatalog);
    		}
		}
    }

	//数据库单元测试前会开始事务，结束时会回滚事务，所以测试方法可以不用关心测试数据的删除

	public void crud() {

		ArchiveCatalog obj = newArchiveCatalog();
		manager.save(obj);
		manager.getEntityDao().flush();

		manager.update(obj);
		manager.getEntityDao().flush();

		assertNotNull(obj.getArchiveCatalogId());

		manager.removeById(obj.getArchiveCatalogId());
		manager.getEntityDao().flush();

	}

	public static ArchiveCatalog newArchiveCatalog() {
		ArchiveCatalog obj = new ArchiveCatalog();

	  	obj.setDrugSellUnitId(new java.lang.Integer("1"));
	  	obj.setSeqNum(new java.lang.Integer("1"));
	  	obj.setFileNumber(new java.lang.String("1"));
	  	obj.setArchiveCatalogName(new java.lang.String("1"));
	  	obj.setYear(new java.lang.String("1"));
	  	obj.setShenpiNum(new java.lang.String("1"));
	  	obj.setPageNum(new java.lang.String("1"));
	  	obj.setTimeLimit(new java.lang.String("1"));
	  	obj.setRemark(new java.lang.String("1"));
		return obj;
	}
}
